home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Creative Computers
/
Creative Computers CD-ROM, Volume 1 (Legendary Design Technologies, Inc.)(1994).iso
/
shareware
/
management
/
priman_1.0
/
priman.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-11-17
|
51KB
|
1,077 lines
/*
Task Priority Manager
Copyright 1993 Barry McConnell
bmccnnll@unix1.tcd.ie
*/
#include <exec/types.h>
#include <exec/memory.h>
#include <exec/execbase.h>
#include <dos/dos.h>
#include <dos/dosextens.h>
#include <intuition/intuition.h>
#include <intuition/gadgetclass.h>
#include <intuition/screens.h>
#include <graphics/text.h>
#include <graphics/gfxbase.h>
#include <libraries/gadtools.h>
#include <libraries/asl.h>
#include <workbench/startup.h>
#include <workbench/workbench.h>
#include <proto/dos.h>
#include <proto/exec.h>
#include <proto/intuition.h>
#include <proto/graphics.h>
#include <proto/gadtools.h>
#include <proto/diskfont.h>
#include <proto/asl.h>
#include <proto/icon.h>
#include <stdio.h>
#include <string.h>
#define WINDOWIDCMP IDCMP_CLOSEWINDOW | IDCMP_REFRESHWINDOW | IDCMP_NEWSIZE | BUTTONIDCMP | LISTVIEWIDCMP | RAWKEY
#define DefFontLength 15 /* including the size */
#define MaxFontLength 30 /* well, have YOU seen any font names longer than this?? */
#define ScrollBarWidth 16
#define LISTGAD 1
#define SLIDERGAD 2
#define BREAKGAD 3
#define KILLGAD 4
#define SETTINGSGAD 5
#define GFONTGAD 6
#define LFONTGAD 7
#define GBOXGAD 8
#define LBOXGAD 9
#define CHECKGAD 10
#define SAVEGAD 11
#define USEGAD 12
#define CANCELGAD 13
void __regargs __chkabort(void) {} /* turn off SAS/C v6 CTRL-C checking */
int showTasks(void);
int handleSettings(struct Screen *, struct Window *,
struct Gadget *, struct Gadget *, struct Gadget *, struct Gadget *,
WORD, WORD, WORD);
struct listType /* standard Node type with extra space to store the original task structure, so we can find it again */
{
struct Node mainNode;
struct Task *mainTask;
};
struct FontRequester *propFontReq = NULL, *monoFontReq = NULL;
struct TextAttr propName = { " ", 0, 0, 0 },
monoName = { " ", 0, 0, 0 };
extern struct ExecBase *SysBase;
static UBYTE *version = "$VER: PriMan 1.0 (03.09.93)";
char *myName = NULL; /* to be filled in from WBStartup message */
int workbench = 0; /* started from CLI or Workbench? */
UWORD osver = 0; /* Kickstart version */
WORD winLeft = 150, winTop = 50, winWidth = 220, winHeight = 270, confirm = 1; /* default settings */
UWORD __chip waitPointer[] =
{
0x0000, 0x0000,
0x0400, 0x07c0,
0x0000, 0x07c0,
0x0100, 0x0380,
0x0000, 0x07e0,
0x07c0, 0x1ff8,
0x1ff0, 0x3fec,
0x3ff8, 0x7fde,
0x3ff8, 0x7fbe,
0x7ffc, 0xff7f,
0x7efc, 0xffff,
0x7ffc, 0xffff,
0x3ff8, 0x7ffe,
0x3ff8, 0x7ffe,
0x1ff0, 0x3ffc,
0x07c0, 0x1ff8,
0x0000, 0x07e0,
0x0000, 0x0000,
};
/*
Display a busy pointer in the current window, and prevent user from
clicking on any gadgets. The immediate flag prevents the short delay
(under 3.x) before the pointer changes.
*/
void busyPointer(struct Window *myWindow, struct Requester *myReq, BOOL immediate)
{
InitRequester(myReq);
Request(myReq, myWindow);
if (osver < 39 || immediate)
SetPointer(myWindow, waitPointer, 16, 16, -6, 0);
else
SetWindowPointer(myWindow, WA_BusyPointer, TRUE,
WA_PointerDelay, TRUE,
TAG_END);
}
/*
Restore the pointer to normal. The keepPointer flag just removes the invisible
requester without restoring the normal pointer image.
*/
void normalPointer(struct Window *myWindow, struct Requester *myReq, BOOL keepPointer)
{
if (!keepPointer)
ClearPointer(myWindow);
EndRequest(myReq, myWindow);
}
/*
Join a text string (task or font name) and a number (priority or size) together.
If it's a task, extra spaces are placed between the two components to make the
string an exact length. If the task has an appropriate CLI number, that will be
added in before the task name.
If it's a font, the routine stops at a dot (i.e. in "x.font"), and places a
single space between it and the size.
There must be length+1 bytes free in dest, because of the \0 char.
*/
void createString(struct Task *task, struct TextAttr *font, char *dest, int length)
{
int numLen, cli, i = 0, j = 0;
char digits[5], clitext[11];
char *name;
APTR bstr;
BYTE maxlen = -1;
if (task) /* dealing with a task or a font? */
{
numLen = sprintf(digits, "%d", task -> tc_Node.ln_Pri); /* saves me writing an integer -> ASCII routine */
if (((task -> tc_Node.ln_Type) == NT_PROCESS) && (cli = ((struct Process *)task) -> pr_TaskNum)) /* is it a process with a CLI attached? */
{
sprintf(clitext, "CLI #%d: ", cli);
for (; (i < length - numLen - 1) && clitext[i]; i++)
dest[i] = clitext[i];
bstr = BADDR(((struct CommandLineInterface *)(BADDR(((struct Process *)task) -> pr_CLI))) -> cli_CommandName);
name = (char *)(bstr)+1;
maxlen = *((BYTE *)bstr);
}
else
name = task -> tc_Node.ln_Name;
}
else /* font */
{
numLen = sprintf(digits, "%d", font -> ta_YSize);
name = font -> ta_Name;
}
for (; (i < length - numLen - 1) && name[j] && maxlen && !((name[j] == '.') && font); i++, j++, maxlen--)
dest[i] = name[j];
do
dest[i++] = ' ';
while ((i < length - numLen) && task); /* only insert one space if it's a font name */
j = 0;
do
dest[i++] = digits[j];
while (digits[j++]);
}
/*
Compare two strings. Like "strcmp" but case-insensitive.
*/
int Compare(char *s, char *t)
{
for (; ((*s & ~32) == (*t & ~32)) && *s; s++, t++) /* sorry, K&R ;-) */
;
return (*s & ~32) - (*t & ~32);
}
/*
Alphabetically insert "node" into "list".
*/
void Sort(struct List *list, struct Node *node)
{
struct Node *temp = list -> lh_Head;
while ((temp -> ln_Succ) && Compare(temp -> ln_Name, node -> ln_Name) < 0)
temp = temp -> ln_Succ;
Insert(list, node, temp -> ln_Pred);
}
/*
Add an Exec task list ("source") onto our own one ("dest").
Allocates memory as necessary, and preserves alphabetical order.
If we just want to add one task, use the last parameter ("single") -
in this case, "source" will be ignored.
*/
int BuildList(struct List *source, struct List *dest, struct Remember **memoryKey, int taskLength, struct Task *single)
{
struct Node *execNode;
struct listType *taskNode;
int success = TRUE;
UBYTE *taskString;
if (single)
{
if ((taskNode = AllocRemember(memoryKey, sizeof(struct listType), MEMF_ANY))
&& (taskString = AllocRemember(memoryKey, taskLength + 1, MEMF_ANY)))
{
createString(single, NULL, taskString, taskLength);
taskNode -> mainNode.ln_Name = taskString;
taskNode -> mainNode.ln_Pri = single -> tc_Node.ln_Pri;
taskNode -> mainTask = single;
Sort(dest, (struct Node *)taskNode);
}
else
success = FALSE;
}
else
{
for (execNode = source -> lh_Head; (execNode -> ln_Succ) && success; execNode = execNode -> ln_Succ)
{
if ((taskNode = AllocRemember(memoryKey, sizeof(struct listType), MEMF_ANY))
&& (taskString = AllocRemember(memoryKey, taskLength + 1, MEMF_ANY)))
{
createString((struct Task *)execNode, NULL, taskString, taskLength);
taskNode -> mainNode.ln_Name = taskString;
taskNode -> mainNode.ln_Pri = execNode -> ln_Pri;
taskNode -> mainTask = (struct Task *)execNode;
Sort(dest, (struct Node *)taskNode);
}
else
success = FALSE;
}
}
return success;
}
/*
Search for given ToolType in array.
Fills in string -> decimal value if found.
*/
void match(char *tool, char **array, WORD *value)
{
char *string;
int temp;
if (string = FindToolType(array, tool)) /* is it there? */
{
sscanf(string, "%d", &temp); /* read it into type "int" */
*value = temp; /* convert to "word" */
}
}
void main(int argc, char *argv[])
{
struct DiskObject *myIcon;
char **tools, *s